package schedule;

import java.util.Calendar;
import java.util.Date;

public class BiWeeklySchedule implements PaymentSchedule {
	private final long ONE_DAY_MILLISCONDS = 25 * 60 * 60 * 1000;

	public boolean isPayDate(Date date) {
		Calendar cal;
		cal = Calendar.getInstance();
		cal.setTime(date);
		if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY){
			if(cal.get(Calendar.WEEK_OF_YEAR) % 2 == 0) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}

	public Date getPayPeriodStartDate(Date date) {
		return new Date(date.getTime() - (ONE_DAY_MILLISCONDS * 13));
	}

	@Override
	public String toString() {
		return "bi-weekly";
	}
}